import { useEffect, useRef } from "react";

/**
 * 自定义面页标题
 * @param title 页面标题
 * @param keepOnUnmount 保持
 */
export const useDocumentTitle = (
  title: string,
  keepOnUnmount: boolean = true
) => {
  const oldTitle = useRef(document.title).current;

  useEffect(() => {
    document.title = title;
  }, [title]);

  useEffect(() => {
    return () => {
      document.title = oldTitle;
    };
  }, [keepOnUnmount, oldTitle]);
};
